package com.simple.card.handle;

import com.simple.card.Utils.ResultVOUtil;
import com.simple.card.VO.ResultVO;
import com.simple.card.exception.CreditException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultVO handle(Exception e) {
        if(e instanceof CreditException) {
            CreditException creditException = (CreditException) e;
            return ResultVOUtil.error(creditException.getCode(),creditException.getMessage());
        }else{
            log.error("[系统未知错误],{}",e);
            return ResultVOUtil.error(-1,"系统未知错误");
        }
    }
}
